package game.buildings;

/**
 *	@(#)Storage.java
 *
 *	The <code>Storage</code> class represents the storage building.
 *	A storage enables the player to store as many goods as the storage
 *	is capable of. It has a fixed capacity and is mannable.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.0 2008/4/23
 */
public final class Storage
extends MannableBuilding
implements Limited
{
	/** The amount of tiles left. */
	private static int tiles;

	/**
	 *	Creates a new <code>Storage</code> instance with the standard size.
	 */
	public Storage() {
		this(2, 1);
	}

	/**
 	 *	Creates a new <code>Storage</code> instance with the given size.
	 *	@param width the width
	 *	@param height the height
	 */
	public Storage(int width, int height) {
		super(BuildingType.STORAGE);
		setSize(width, height);
	}

	/**
	 *	Sets the size of the storage to the given values.
	 *	@param width the new width
	 *	@param height the new height
	 */
	public void setSize(int width, int height) {
		polygon = new java.awt.Polygon(new int[]{0, width, width, 0}, new int[]{0, 0, height, height}, 4);
		spin = (width != height ? 2 : 1);
	}

	/**
	 *	Returns the capacity.
	 *	@return the capacity
	 */
	public int getCapacity() {
		java.awt.Dimension size = polygon.getBounds().getSize();
		return size.width * size.height;
	}

	/**
	 *	Resets the amount of tiles to the initial value.
	 */
	public static void resetTiles() {
		tiles = 16;
	}

	/**
	 *	Decreases the amount of tiles left by the given value.
	 *	@param n the amount
	 */
	public void decreaseTiles(int n) {
		tiles -= n;
	}

	/**
	 *	Returns the amount of tiles left.
	 *	@return the amount of tiles left
	 */
	public int getTiles() {
		return tiles;
	}
}